define [
  'chaplin'
  'views/layout_view'
], (Chaplin, LayoutView) ->

  'use strict'

  class BaseController extends Chaplin.Controller

    # Additional Attributes
    # =============================================================

    # Objeto onde são incluídas variáveis persistentes entre os controllers
    globals: {}
    menuVisible : true

    # Override Methods
    # =============================================================

    initialize: ->
      @globals = _.clone window.AppData.CNTRL_GLOBALS
      @subscribeEvent 'layout:ready', => @publishEvent 'layout:updateMenu', @globals.userData?.authorities
      window.AppData.CNTRL_GLOBALS = {}
      super

    beforeAction: ->
      $('#app-container').find('.load-container').remove()
      @compose 'site', LayoutView
      do @updateMenu

    dispose: ->
      super
      @publishEvent 'load:show'

    updateMenu: ->
      if @menuVisible
        @publishEvent 'show:menu'
      else
        @publishEvent 'hide:menu'